package org.apache.httpclient;

import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;

public class A
{
    private List<Key> list = new LinkedList<>();
    
    A(InputStream is,int cancalKey){
        PressTread t = new PressTread(list, is, cancalKey);
        t.start();
    }
    
    class PressTread extends Thread{
        List<Key> pressList;
        InputStream is ;
        int cancalKey;
        PressTread(List<Key> pressList,InputStream is,int cancalKey){
            this.pressList = pressList;
            this.is = is;
            this.cancalKey = cancalKey;
        }
        
        @Override
        public void run()
        {
            int keyValue =0;
            while(true){
                try
                {
                    keyValue = is.read();
                    this.pressList.add(new Key(keyValue,System.currentTimeMillis()));
                    if(cancalKey == keyValue) break;
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                    break;
                }
            }
            System.out.println(this.pressList);
        }
    }
    
    class Key{
        int keyValue;
        long time;
        Key(int keyValue,long time){
            this.keyValue=keyValue;
            this.time=time;
        }
        @Override
        public String toString()
        {
            return "Key {keyValue=" + keyValue + ", time=" + time + "}";
        }
    }
    
    public static void main(String[] args)
    {
      new A(System.in,(int)'\n');
    }
}
